package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.union.cross.CrossUnionProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.union.CrossUnionMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C_UNION_POSITION_SET, desc = "设置职位")
public class CrossSetPositionCmd extends CrossCommand {

	private int position;

	private long operateUserId;

	private boolean isBack;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		CrossUnionProto.UnionPositionSetCrossReqMsg reqMsg = CrossUnionProto.UnionPositionSetCrossReqMsg.parseFrom(packet.getBytes());
		position = reqMsg.getPosition();
		operateUserId = reqMsg.getUserId();
		isBack = reqMsg.getIsBack();
		return true;
	}

	@Override
	public void execute(YanQuMessage packet) throws Exception {

		MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_UNION_POSITION_SET,
				CrossUnionMgr.setPosition(packet.getPlayerId(), operateUserId, position, isBack)));

	}

	@Override
	public void sendData() {

	}

}
